package com.yygo.model;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tiansha on 2015/6/23.
 */
@Entity
@Table(name = "vehicle_brand")
public class VehicleBrand extends BaseObject {
    private static final long serialVersionUID = -4577429555303308703L;
    private Long id;
    private String letter;
    private String brand;
    private List<VehicleSeries> vehicleSeries = new ArrayList();

    public VehicleBrand() {}

    public VehicleBrand(String letter, String brand) {
        this.letter = letter;
        this.brand = brand;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(length = 1)
    public String getLetter() {
        return letter;
    }

    public void setLetter(String letter) {
        this.letter = letter;
    }

    @Column(length = 50)
    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    @OneToMany(fetch = FetchType.EAGER,mappedBy = "vehicleBrand", cascade = CascadeType.REMOVE)
    @Fetch(FetchMode.SELECT)
    public List<VehicleSeries> getVehicleSeries() {
        return vehicleSeries;
    }

    public void setVehicleSeries(List<VehicleSeries> vehicleSeries) {
        this.vehicleSeries = vehicleSeries;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        VehicleBrand vehicleBrand = (VehicleBrand) o;

        if (brand.equals(vehicleBrand.brand)) {
            return true;
        }

        return false;
    }

    public int hashCode() {
        int result;
        result = (brand != null ? brand.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "VehicleBrand{" +
                "id=" + id +
                ", brand='" + brand +
                '}';
    }
}
